package com.spider.stringdemo;

public class StringDemo2 {
    public static void main(String[] args) {
        //目标：生成验证码

        System.out.println(getCode(4));
        System.out.println(getCode(6));
    }
    //生成指定位数的随机验证码返回，每位可能是数字或者大小写字母
    //帮我用String变量记住全部用到的字符
    public static String getCode(int n){
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        String code = "";
        for (int i = 0; i < n; i++){
            code += str.charAt( (int)(Math.random() * str.length()) );
        }
        return code;
    }
}

